package com.jxl.service;

import com.jxl.bean.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * WebSocket业务层：对外提供发送消息的接口（Controller可调用）
 */
@Service
public class WebSocketService {
    // 注入WebSocket实例（Spring会管理@ServerEndpoint标注的Bean）
    @Autowired
    private WebSocket webSocket;

    /**
     * 发送广播消息
     */
    public void sendAll(String message) {
        webSocket.sendAllMessage(message);
    }

    /**
     * 发送单点消息
     */
    public void sendOne(String userId, String message) {
        webSocket.sendOneMessage(userId, message);
    }

    /**
     * 发送批量消息
     */
    public void sendMore(String[] userIds, String message) {
        webSocket.sendMoreMessage(userIds, message);
    }
}